package org.osomit.sacct.account.manager.impl;

import org.osomit.sacct.account.registry.iface.AccountRegistry;
import org.osomit.sacct.account.registry.iface.AccountRegistryLoader;
import org.osomit.sacct.account.manager.iface.AccountManager;
import org.osomit.sacct.entity.ApplicationAccount;

import java.util.List;

import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * @author Jian Fang (John.Jian.Fang@gmail.com)
 *
 * Date: Jun 30, 2009
 */
@Singleton
public class AccountManagerImpl implements AccountManager {

    private AccountRegistry registry;

    private AccountRegistryLoader registryLoader;

    public AccountRegistry getRegistry() {
        return registry;
    }

    @Inject
    public void setRegistry(AccountRegistry registry) {
        this.registry = registry;
    }

    public AccountRegistryLoader getRegistryLoader() {
        return registryLoader;
    }
    
    @Inject
    public void setRegistryLoader(AccountRegistryLoader registryLoader) {
        this.registryLoader = registryLoader;
    }

    public void addAccount(String clientId, ApplicationAccount account) {
        this.registry.addAccount(clientId, account);
    }

    public void updateAccount(String clientId, ApplicationAccount account) {
        this.registry.updateAccount(clientId, account);
    }

    public void deleteAccount(String clientId, String accountName) {
        this.registry.deleteAccount(clientId, accountName);
    }

    public void addAllAccounts(String clientId, List<ApplicationAccount> accounts) {
        this.registry.addAllAccounts(clientId, accounts);
    }

    public ApplicationAccount getAccount(String clientId, String accountName) {
        return this.registry.getAccount(clientId, accountName);
    }

    public List<ApplicationAccount> getAllAccounts(String clientId) {
        return this.registry.getAllAccounts(clientId);
    }

    public void clear() {
        this.registry.clear();
    }

    public void load(String password) {
        this.registryLoader.load(this.registry, password);
    }

    public void save(String password){
        this.registryLoader.persist(this.registry, password);
    }
}
